﻿package mortal.game.view.copy.guildDefenseCopy.panel
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mainUI.smallMap.view.data.*;
    import mortal.game.view.skill.*;
    import mortal.mvc.core.*;

    public class GuildDefenseTowerRender extends GCellRenderer
    {
        private var _name:GTextFiled;
        private var _level:GTextFiled;
        private var _dec:GTextFiled;
        private var _nextlevel:GTextFiled;
        private var _gotoKill:GTextFiled;
        private var _giveBtn:GTextFiled;
        private var _giveAllBtn:GTextFiled;
        private var _towerInfo:SGuildTowerInfo;
        private var _icon:GBitmap;
        private var _tower:GImageBitmap;
        private var _smallMapTypeIconData:SmallMapTypeIconData;
        private var _totalNum:int;
        private var _type:int;

        public function GuildDefenseTowerRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._name = UIFactory.gTextField("", 40, 0, 65, 20, this);
            this._level = UIFactory.gTextField("", 70, 0, 50, 50, this, GlobalStyle.textFormatItemGreen);
            this._dec = UIFactory.gTextField("", 40, 17, 200, 20, this);
            this._nextlevel = UIFactory.gTextField("", 40, 34, 200, 20, this, GlobalStyle.textFormatDanLan);
            var _loc_1:* = GlobalStyle.textFormatItemGreen;
            _loc_1.underline = true;
            this._gotoKill = UIFactory.gTextField(Language.getString(35260), 145, 34, 100, 20, null, _loc_1, true);
            this._gotoKill.configEventListener(TextEvent.LINK, this.gotoKillBoss);
            this._giveBtn = UIFactory.gTextField(Language.getString(35261), 147, 34, 50, 20, this, _loc_1, true);
            this._giveBtn.configEventListener(MouseEvent.CLICK, this.upgradeTower);
            this._giveAllBtn = UIFactory.gTextField(Language.getString(35262), 180, 34, 50, 20, this, _loc_1, true);
            this._giveAllBtn.configEventListener(MouseEvent.CLICK, this.upgradeTower);
            this._tower = UIFactory.gImageBitmap("", -3, -3, this);
            this._icon = UIFactory.gBitmap(ImagesConst.BossDrop_7, 124, 36, this);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._name.dispose(param1);
            this._name = null;
            this._level.dispose(param1);
            this._level = null;
            this._dec.dispose(param1);
            this._dec = null;
            this._nextlevel.dispose(param1);
            this._nextlevel = null;
            this._icon.dispose(param1);
            this._icon = null;
            this._tower.dispose(param1);
            this._tower = null;
            this._gotoKill.dispose(param1);
            this._gotoKill = null;
            this._giveBtn.dispose(param1);
            this._giveBtn = null;
            this._giveAllBtn.dispose(param1);
            this._giveAllBtn = null;
            this._towerInfo = null;
            this._smallMapTypeIconData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._towerInfo = param1.info as SGuildTowerInfo;
            this._smallMapTypeIconData = param1.IconData as SmallMapTypeIconData;
            this._totalNum = param1.totalNum;
            this._type = param1.index;
            this._nextlevel.text = Language.getString(35263) + this._towerInfo.piece + "/" + this._towerInfo.levelUpPieces;
            var _loc_2:* = GuildDefenseConfig.instance.getTowerInfoByTypeAndLevel(this._type, this._towerInfo.level);
            var _loc_3:* = BossConfig.instance.getRefresById(_loc_2.towerRefreshId);
            var _loc_4:* = BossConfig.instance.getInfoByCode(_loc_3.bossCode);
            var _loc_5:* = SkillConfig.instance.getInfoById(_loc_2.towerBossSkillId);
            if (_loc_5)
            {
                var _loc_6:* = Language.getString(35264) + SkillUtil.alySkillDesc(_loc_5);
                this._dec.htmlText = Language.getString(35264) + SkillUtil.alySkillDesc(_loc_5);
                this.toolTipData = _loc_6;
            }
            this._name.text = _loc_4.name;
            this._level.text = "(Lv" + this._towerInfo.level + ")";
            this._level.x = this._name.x + this._name.textWidth + 5;
            if (this._tower.bitmapData == null)
            {
                this._tower.imgUrl = "GuildDefenseTower_" + param1.index;
            }
            return;
        }// end function

        private function upgradeTower(event:MouseEvent) : void
        {
            if (this._totalNum <= 0)
            {
                return MsgManager.showRollTipsMsg(Language.getString(35265), MsgRollTipsType.msgRollTips3);
            }
            var _loc_2:* = new Object();
            if (event.target == this._giveBtn)
            {
                if (this._totalNum < 10)
                {
                    return MsgManager.showRollTipsMsg(Language.getString(35265), MsgRollTipsType.msgRollTips3);
                }
                _loc_2.type = this._type;
                _loc_2.num = 10;
            }
            else if (event.target == this._giveAllBtn)
            {
                _loc_2.type = this._type;
                _loc_2.num = this._totalNum;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildDefenseTowerUpgrade, _loc_2));
            return;
        }// end function

        private function gotoKillBoss(event:TextEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SmallMapTypeIconClick, this._smallMapTypeIconData));
            return;
        }// end function

    }
}
